﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ncp.Business;

namespace ncp.Web.uc
{
    public partial class menu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    //获取地址
                    var url = Request.Url.ToString().ToLower();
                    var type = Request.QueryString["channel"];
                    IList<string> pages = new List<string>();
                    pages.Add("/index.aspx");
                    pages.Add("/productsupply/index.html");
                    pages.Add("/buyingleads/index.html");
                    pages.Add("/movement/index.html");
                    pages.Add("/scientific/index.html");
                    pages.Add("/join/index.html");
                    IList<string> name = new List<string>();
                    name.Add("首页");
                    name.Add("产品供应");
                    name.Add("求购信息");
                    name.Add("浓情动态");
                    name.Add("科普知识");
                    name.Add("招商加盟");
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < pages.Count; i++)
                    {
                        builder.Append("<li");
                        if (url.Contains("index.aspx")&&i==0)
                        {
                            builder.Append(" class=\"on\" ");
                        }
                        else if (url.Replace(".aspx","").Contains(pages[i].Split('/')[1]) || (url.Contains("product") && i == 1) ||
                            (type == "001" && i == 2) || (type == "010" && i == 5) ||
                            ((type == "003" || type == "004" || type == "005" || type == "007") && i == 4) || (type == "002"&&i==3))
                        {
                            builder.Append(" class=\"on\" ");
                        }
                        builder.AppendFormat("><a href=\"{0}\">{1}</a></li>", pages[i], name[i]);
                    }
                    string html = builder.ToString();
                    if (builder.ToString().IndexOf("on")==-1)
                    {
                        html = "<li class=\"on\" " + builder.ToString().Substring(3);
                    }
                    ltMenu.Text = html;
                }
                catch (Exception ex)
                {
                    Response.Redirect("/shop/error.aspx");
                }
                
            }
        }
    }
}